package com.lc.cehui.ui.activity.mine;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.cehui.R;
import com.lc.cehui.app.AppActivity;
import com.lc.cehui.base.BaseDialog;
import com.lc.cehui.dialog.MenuDialog;
import com.lc.cehui.http.request.CouponInsertApi;
import com.lc.cehui.http.response.BaseBean;
import com.lc.cehui.other.IntentKey;
import com.lc.cehui.util.SPUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CreateCouponActivity extends AppActivity {
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.tv_term)
    TextView tvTerm;
    @BindView(R.id.et_num)
    EditText etNum;
    @BindView(R.id.et_denomination)
    EditText etDenomination;
    @BindView(R.id.et_quota)
    EditText etQuota;
    @BindView(R.id.et_start_time)
    EditText etStartTime;
    @BindView(R.id.et_end_time)
    EditText etEndTime;
    @BindView(R.id.tv_des)
    EditText tvDes;
    @BindView(R.id.et_should)
    EditText etShould;
    @BindView(R.id.ll_quota)
    LinearLayout llQuota;
    private int type;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_createcoupon;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.tv_term, R.id.bt_submit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_term:
                new MenuDialog.Builder(getActivity())
                        .setList("无门槛","需满减")
                        .setTitle("请选择操作")
                        .setListener(new MenuDialog.OnListener<String>() {
                            @Override
                            public void onSelected(BaseDialog dialog, int position, String string) {
                                switch (position) {
                                    case 0:
                                        type = 1;
                                        llQuota.setVisibility(View.GONE);
                                        break;
                                    case 1:
                                        type = 2;
                                        llQuota.setVisibility(View.VISIBLE);


                                        break;
                                }
                            }
                                    @Override
                                    public void onCancel(BaseDialog dialog) {

                                    }
                                }).show();
            case R.id.bt_submit:
                coupon_insert();
                break;
        }
    }

    private void coupon_insert() {
        EasyHttp.post(this)
                .api(new CouponInsertApi().setUserid(SPUtil.get(this, IntentKey.USERID,0)).setType(type).setStart_time(etStartTime.getText().toString()).setEnd_time(etEndTime.getText().toString()).setCircul(etNum.getText().toString()).setRed_price(etDenomination.getText().toString()).setName(etName.getText().toString()).setShold_price(etQuota.getText().toString()).setText(tvDes.getText().toString()))
                .request(new HttpCallback<BaseBean>(this) {

                    @Override
                    public void onSucceed(BaseBean data) {

                       if (callBackCode(data)){
                           toast(data.getMsg());
                           finish();
                       }

                    }
                });
    }

}
